package com.itbbfx.controller.department;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itbbfx.entity.*;
import com.itbbfx.service.department.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("departmentCenter")
public class DepartmentCenterController {
    @Autowired
    private DepartmentService departmentService;
    @Autowired
    private RegisteredTypeService registeredTypeService;
    @Autowired
    private ProjectTypeService projectTypeService;
    @Autowired
    private UnitService unitService;
    @Autowired
    private DoctorService doctorService;
    @Autowired
    private PaibanService paibanService;
    @Autowired
    private MainService mainService;
    @Autowired
    private FinanceService financeService; //
    /*
     * 查询科室
     * */
    @RequestMapping("departmentList")
    public Object DepartmentList(Departments departments, Integer page, Integer limit){
        PageHelper.startPage(page, limit);
        List<Departments> listAll = departmentService.departmentList(departments);
        PageInfo pageInfo = new PageInfo(listAll);
        Map<String, Object> tableData = new HashMap<String, Object>();
        //这是layui要求返回的json数据格式
        tableData.put("code", 0);
        tableData.put("msg", "");
        //将全部数据的条数作为count传给前台（一共多少条）
        tableData.put("count", pageInfo.getTotal());
        //将分页后的数据返回（每页要显示的数据）
        tableData.put("data", pageInfo.getList());
        return tableData;
    }
    /*
     * 添加科室
     * */
    @RequestMapping("addDepartment")
    public Object addDepartment(Departments departments){
        int count = departmentService.count(departments);
        if(count==0){
            int i = departmentService.addDepartment(departments);
            if(i==1){
                return "添加成功";
            }else{
                return "添加失败";
            }
        }else{
            return departments.getDepartment()+"已存在";
        }

    }
    /*
     * 修改科室
     * */
    @RequestMapping("editDepartment")
    public Object editDepartment(Departments departments){
        int i = departmentService.editDepartment(departments);
        if(i==1){
            return "修改成功";
        }else{
            return "修改失败";
        }

    }
    /*
     * 删除科室
     * */
    @RequestMapping("deleteDepartment")
    public Object deleteDepartment(Integer departmentId){
        int i = departmentService.deleteDepartment(departmentId);
        if(i==1){
            return "删除成功";
        }else{
            return "删除失败";
        }


    }
    /*
     * 查询
     * */
    @RequestMapping("registeredTypeList")
    public Object registeredTypeList(Registeredtype registeredtype, Integer page, Integer limit){
        PageHelper.startPage(page, limit);
        List<Registeredtype> listAll = registeredTypeService.registeredTypeList(registeredtype);
        PageInfo pageInfo = new PageInfo(listAll);
        Map<String, Object> tableData = new HashMap<String, Object>();
        //这是layui要求返回的json数据格式
        tableData.put("code", 0);
        tableData.put("msg", "");
        //将全部数据的条数作为count传给前台（一共多少条）
        tableData.put("count", pageInfo.getTotal());
        //将分页后的数据返回（每页要显示的数据）
        tableData.put("data", pageInfo.getList());

        return tableData;
    }
    /*
     * 添加类型
     * */
    @RequestMapping("addRegisteredType")
    public Object addRegisteredType(Registeredtype registeredtype){
        int count = registeredTypeService.count(registeredtype);
        if(count==0){
            int i = registeredTypeService.addRegisteredType(registeredtype);
            if(i==1){
                return "添加成功";
            }else{
                return "添加失败";
            }
        }else{
            return registeredtype.getType()+"已存在";
        }

    }
    /*
     * 修改类型
     * */
    @RequestMapping("editRegisteredType")
    public Object editRegisteredType(Registeredtype registeredtype){
        int i = registeredTypeService.editRegisteredType(registeredtype);
        if(i==1){
            return "修改成功";
        }else{
            return "修改失败";
        }

    }
    /*
     * 删除类型
     * */
    @RequestMapping("deleteType")
    public Object deleteType(Integer registeredId){
        int i = registeredTypeService.deleteType(registeredId);
        if(i==1){
            return "删除成功";
        }else{
            return "删除失败";
        }
    }

    /*
     * 查询生产项目大类
     * */
    @RequestMapping("findAllProjecttype")
    public Object ProjecttypeList(Projecttype projecttype, Integer page, Integer limit){

        PageHelper.startPage(page, limit);
        List<Projecttype> listAll = projectTypeService.findAllProjecttype(projecttype);
        PageInfo pageInfo = new PageInfo(listAll);
        Map<String, Object> tableData = new HashMap<String, Object>();
        //这是layui要求返回的json数据格式
        tableData.put("code", 0);
        tableData.put("msg", "");
        //将全部数据的条数作为count传给前台（一共多少条）
        tableData.put("count", pageInfo.getTotal());
        //将分页后的数据返回（每页要显示的数据）
        tableData.put("data", pageInfo.getList());

        return tableData;
    }
    /*
     * 添加生产项目大类
     * */
    @RequestMapping("addProjecttype")
    public Object addProjecttype(Projecttype projecttype){
        int i1 = projectTypeService.count1(projecttype);
        if(i1==0){
            int i = projectTypeService.addProjecttype(projecttype);
            if(i==1){
                return "添加成功";
            }else{
                return "添加失败";
            }
        }else{
            return projecttype.getProjectName()+"已存在";
        }

    }
    /*
     * 修改生产项目大类
     * */
    @RequestMapping("editProjecttype")
    public Object editProjecttype(Projecttype projecttype){
        int i = projectTypeService.editProjecttype(projecttype);
        if(i==1){
            return "修改成功";
        }else{
            return "修改失败";
        }
    }
    /*
     * 删除生产项目大类
     * */
    @RequestMapping("deleteProjecttype")
    public Object deleteProjecttype(Integer projectId){
        int i = projectTypeService.deleteProjecttype(projectId);
        if(i==1){
            return "删除成功";
        }else{
            return "删除失败";
        }
    }
    /*
     * 查询收费类型
     * */
    @RequestMapping("findAllMoneytype")
    public Object MoneytypeList(Moneytype moneytype, Integer page, Integer limit){
        PageHelper.startPage(page, limit);
        List<Moneytype> listAll = projectTypeService.findAllMoneytype(moneytype);
        PageInfo pageInfo = new PageInfo(listAll);
        Map<String, Object> tableData = new HashMap<String, Object>();
        //这是layui要求返回的json数据格式
        tableData.put("code", 0);
        tableData.put("msg", "");
        //将全部数据的条数作为count传给前台（一共多少条）
        tableData.put("count", pageInfo.getTotal());
        //将分页后的数据返回（每页要显示的数据）
        tableData.put("data", pageInfo.getList());

        return tableData;
    }
    /*
     * 添加收费类型
     * */
    @RequestMapping("addMoneytype")
    public Object addMoneytype(Moneytype moneytype){
        int i1 = projectTypeService.count4(moneytype);
        if(i1==0){
            int i = projectTypeService.addMoneytype(moneytype);
            if(i==1){
                return "添加成功";
            }else{
                return "添加失败";
            }
        }else{
            return moneytype.getMoneytype()+"已存在";
        }

    }
    /*
     * 修改收费类型
     * */
    @RequestMapping("editMoneytype")
    public Object editMoneytype(Moneytype moneytype){
        int i = projectTypeService.editMoneytype(moneytype);
        if(i==1){
            return "修改成功";
        }else{
            return "修改失败";
        }

    }
    /*
     * 删除收费类型
     * */
    @RequestMapping("deleteMoneytype")
    public Object deleteMoneytype(Integer moneyId){
        int i = projectTypeService.deleteMoneytype(moneyId);
        if(i==1){
            return "删除成功";
        }else{
            return "删除失败";
        }
    }
    /*
     * 查询门诊收费项
     * */
    @RequestMapping("findAllOutpatienttype")
    public Object OutpatienttypeList(Outpatienttype outpatienttype, Integer page, Integer limit){

        PageHelper.startPage(page, limit);
        List<Outpatienttype> listAll = projectTypeService.findAllOutpatienttype(outpatienttype);
        PageInfo pageInfo = new PageInfo(listAll);
        Map<String, Object> tableData = new HashMap<String, Object>();
        //这是layui要求返回的json数据格式
        tableData.put("code", 0);
        tableData.put("msg", "");
        //将全部数据的条数作为count传给前台（一共多少条）
        tableData.put("count", pageInfo.getTotal());
        //将分页后的数据返回（每页要显示的数据）
        tableData.put("data", pageInfo.getList());

        return tableData;
    }

    /*
     * 查询计量单位
     * */
    @RequestMapping("findAllUnit")
    public Object UnitList(){
        List<Unit> listAll = unitService.findAllUnit(null);
        return listAll;
    }
    @RequestMapping("findAllProjecttype1")
    public Object ProjecttypeList(){

        List<Projecttype> listAll = projectTypeService.findAllProjecttype(null);

        return listAll;
    }
    /*

     * 添加门诊收费项
     * */
    @RequestMapping("addOutpatienttype")
    public Object addOutpatienttype(Outpatienttype outpatienttype, Integer projectId, Integer unitId){
        outpatienttype.setBigprojectId(projectId);
        outpatienttype.setUnit(unitId);
        int i1 = projectTypeService.count2(outpatienttype);
        if(i1==0){
            int i = projectTypeService.addOutpatienttype(outpatienttype);
            if(i==1){
                return "添加成功";
            }else{
                return "添加失败";
            }
        }else {
            return outpatienttype.getProjectName()+"已存在";
        }

    }
    /*
     * 修改门诊收费项
     * */
    @RequestMapping("editOutpatienttype")
    public Object editOutpatienttype(Outpatienttype outpatienttype, Integer projectId, Integer unitId){
        outpatienttype.setBigprojectId(projectId);
        outpatienttype.setUnit(unitId);
        int i = projectTypeService.editOutpatienttype(outpatienttype);
        if(i==1){
            return "修改成功";
        }else{
            return "修改失败";
        }


    }
    /*
     * 删除门诊收费项
     * */
    @RequestMapping("deleteOutpatienttype")
    public Object deleteOutpatienttype(Integer outpatientId){
        int i = projectTypeService.deleteOutpatienttype(outpatientId);
        if(i==1){
            return "删除成功";
        }else{
            return "删除失败";
        }
    }
    /*------------------------------------------------------------------------*/
    /*
     * 查询住院收费项
     * */
    @RequestMapping("findAllInoutpatienttype")
    public Object InoutpatienttypeList(Inoutpatienttype inoutpatienttype, Integer page, Integer limit){

        PageHelper.startPage(page, limit);
        List<Inoutpatienttype> listAll = projectTypeService.findAllInoutpatienttype(inoutpatienttype);
        PageInfo pageInfo = new PageInfo(listAll);
        Map<String, Object> tableData = new HashMap<String, Object>();
        //这是layui要求返回的json数据格式
        tableData.put("code", 0);
        tableData.put("msg", "");
        //将全部数据的条数作为count传给前台（一共多少条）
        tableData.put("count", pageInfo.getTotal());
        //将分页后的数据返回（每页要显示的数据）
        tableData.put("data", pageInfo.getList());

        return tableData;
    }
    /*
     * 查询计量单位
     * */
    @RequestMapping("findAllUnit1")
    public Object findAllUnit1(){
        List<Unit> listAll = unitService.findAllUnit(null);
        return listAll;
    }
    @RequestMapping("findAllProjecttype2")
    @ResponseBody
    public Object findAllProjecttype2(){

        List<Projecttype> listAll = projectTypeService.findAllProjecttype(null);

        return listAll;
    }
    /*
     * 添加住院收费项
     * */
    @RequestMapping("addInoutpatienttype")
    public Object addInoutpatienttype(Inoutpatienttype inoutpatienttype, Integer projectId, Integer unitId){

        inoutpatienttype.setBigprojectId(projectId);
        inoutpatienttype.setUnit(unitId);
        int i1 = projectTypeService.count3(inoutpatienttype);
        if(i1==0){
            int i = projectTypeService.addInoutpatienttype(inoutpatienttype);
            if(i==1){
                return "添加成功";
            }else{
                return "添加失败";
            }
        }else {
            return inoutpatienttype.getProjectName()+"已存在";
        }

    }
    /*
     * 修改住院收费项
     * */
    @RequestMapping("editInoutpatienttype")
    @ResponseBody
    public Object editInoutpatienttype(Inoutpatienttype inoutpatienttype, Integer projectId, Integer unitId){
        inoutpatienttype.setBigprojectId(projectId);
        inoutpatienttype.setUnit(unitId);

        int i = projectTypeService.editInoutpatienttype(inoutpatienttype);
        if(i==1){
            return "修改成功";
        }else{
            return "修改失败";
        }

    }
    /*
     * 删除住院收费项
     * */
    @RequestMapping("deleteInoutpatienttype")
    public Object deleteInoutpatienttype(Integer inoutpatientId){
        int i = projectTypeService.deleteInoutpatienttype(inoutpatientId);
        if(i==1){
            return "删除成功";
        }else{
            return "删除失败";
        }
    }
    /*------------------------------------------------------------*/
    /*
     * 查询床位
     * */
    @RequestMapping("findAllBed")
    public Object BedList(Bed bed, Integer page, Integer limit){
        System.out.println(bed.getBedname());
        PageHelper.startPage(page, limit);
        List<Bed> listAll = projectTypeService.findAllBed(bed);
        PageInfo pageInfo = new PageInfo(listAll);
        Map<String, Object> tableData = new HashMap<String, Object>();
        //这是layui要求返回的json数据格式
        tableData.put("code", 0);
        tableData.put("msg", "");
        //将全部数据的条数作为count传给前台（一共多少条）
        tableData.put("count", pageInfo.getTotal());
        //将分页后的数据返回（每页要显示的数据）
        tableData.put("data", pageInfo.getList());

        return tableData;
    }
    /*
     * 添加床位
     * */
    @RequestMapping("addBed")
    public Object addBed(Bed bed){

        int i1 = projectTypeService.count5(bed);
        if(i1==0){
            int i = projectTypeService.addBed(bed);
            if(i==1){
                return "添加成功";
            }else{
                return "添加失败";
            }
        }else {
            return bed.getBedname()+"已存在";
        }

    }
    /*
     * 修改床位
     * */
    @RequestMapping("editBed")
    public Object editBed(Bed bed){

        int i = projectTypeService.editBed(bed);
        if(i==1){
            return "修改成功";
        }else{
            return "修改失败";
        }
    }


    /*
     * 删除床位
     * */
    @RequestMapping("deleteBed")
    public Object deleteBed(Integer bedId){
        int i1 = projectTypeService.checkCount(bedId);
        if(i1==1){
            return "该床位还有病人" ;
        }else {
            int i = projectTypeService.deleteBed(bedId);
            if(i==1){
                return "删除成功";
            }else{
                return "删除失败";
            }
        }

    }
    /*
     * 查询科室
     * */
    @RequestMapping("departmentsList")
    public Object DepartmentsList(){
        List<Departments> listAll = departmentService.departmentList(null);
        return listAll;
    }
    /*
     * 查询医生
     * */
    @RequestMapping("doctorList")
    public Object doctorList(Doctor doctor, Integer page, Integer limit){
        PageHelper.startPage(page, limit);
        List<Doctor> listAll = doctorService.doctorList(doctor);
        PageInfo pageInfo = new PageInfo(listAll);
        Map<String, Object> tableData = new HashMap<String, Object>();
        //这是layui要求返回的json数据格式
        tableData.put("code", 0);
        tableData.put("msg", "");
        //将全部数据的条数作为count传给前台（一共多少条）
        tableData.put("count", pageInfo.getTotal());
        //将分页后的数据返回（每页要显示的数据）
        tableData.put("data", pageInfo.getList());

        return tableData;
    }
    /*
     * 添加医生
     * */
    @RequestMapping("addDoctor")
    public Object addDoctor(Doctor doctor, Paiban paiban){
        int count = doctorService.count(doctor);
        if(count==0){
            int i = doctorService.addDoctor(doctor);
            if(i==1){
                return "添加成功";
            }else{
                return "添加失败";
            }
        }else{
            return doctor.getDoctorName()+"已存在";
        }

    }
    /*
     * 修改医生
     * */
    @RequestMapping("editDoctor")
    public Object editDoctor(Doctor doctor){
        int i = doctorService.editDoctor(doctor);
        if(i==1){
            return "修改成功";
        }else{
            return "修改失败";
        }

    }
    /*
     * 删除医生
     * */
    @RequestMapping("deleteDoctor")
    public Object deleteDoctor(Integer doctorId){
        int i1 = doctorService.checkCount(doctorId);
        if(i1>0){
            return "该医生还有病人";
        }else{
            int i = doctorService.deleteDoctor(doctorId);
            if(i==1){
                return "删除成功";
            }else{
                return "删除失败";
            }
        }

    }
    /*
     * 查询科室
     * */
    @RequestMapping("findAllDepartments")
    public Object findAllDepartments(){
        List<Departments> allDepartments = doctorService.findAllDepartments();
        return allDepartments;
    }
    /*
     * 查询类型
     * */
    @RequestMapping("findAllRegisteredtype")
    public Object findAllRegisteredtype(){
        List<Registeredtype> allRegisteredtype = doctorService.findAllRegisteredtype();
        return allRegisteredtype;
    }
    @RequestMapping("findAllPaiban")
    public Object findAllPaiban(Paiban paiban, Integer page, Integer limit){
        PageHelper.startPage(page, limit);
        List<Paiban> allPaiban = paibanService.findAllPaiban(paiban);
        PageInfo pageInfo = new PageInfo(allPaiban);
        Map<String, Object> tableData = new HashMap<String, Object>();
        //这是layui要求返回的json数据格式
        tableData.put("code", 0);
        tableData.put("msg", "");
        //将全部数据的条数作为count传给前台（一共多少条）
        tableData.put("count", pageInfo.getTotal());
        //将分页后的数据返回（每页要显示的数据）
        tableData.put("data", pageInfo.getList());
        return tableData;
    }
    @RequestMapping("editPaiban")
    public Object editPaiban(Paiban paiban){
        int count = paibanService.count(paiban.getDoctorId());
        System.out.println(count);
        if(count==1){
            paibanService.editPaiban(paiban);

        }else if(count==0){

            paiban.setDoctorId(paiban.getDoctorId());
            paibanService.insertPaiban(paiban);
            paibanService.editPaiban(paiban);
        }
        return "修改成功";
    }
    @RequestMapping("findAllBan")
    public Object findAllBan(){
        List<Ban> allBan = paibanService.findAllBan();
        return allBan;
    }
    @RequestMapping("one")
    public Object one(){
        List<Paiban> one = mainService.one();
        return one;
    }
    @RequestMapping("two")
    public Object two(){
        List<Paiban> two = mainService.two();
        return two;
    }
    @RequestMapping("three")
    public Object three(){
        List<Paiban> three = mainService.three();
        return three;
    }
    @RequestMapping("four")
    public Object four(){
        List<Paiban> four = mainService.four();
        return four;
    }
    @RequestMapping("five")
    public Object five(){
        List<Paiban> five = mainService.five();
        return five;
    }
    @RequestMapping("six")
    public Object six(){
        List<Paiban> six = mainService.six();
        return six;
    }
    @RequestMapping("seven")
    public Object seven(){
        List<Paiban> seven = mainService.seven();
        return seven;
    }
    /*
     * 查询当天门诊人数
     * */
    @RequestMapping("currentNum")
    public Object currentNum(){
        int currentNum = mainService.currentNum();
        return currentNum;
    }
    /*
     * 查询所有人数
     * */
    @RequestMapping("Total")
    public Object Total(){
        int Total = mainService.Total();
        return Total;
    }
    /*
     * 查询住院所有人数
     * */
    @RequestMapping("zhuyuanTotal")
    public Object zhuyuanTotal(){
        int zhuyuanTotal = mainService.zhuyuanTotal();
        return zhuyuanTotal;
    }
    /*
     * 查询当天住院所有人数
     * */
    @RequestMapping("currentZhuYuan")
    public Object currentZhuYuan(){
        int currentZhuYuan = mainService.currentZhuYuan();
        return currentZhuYuan;
    }
    /*门诊当天收入*/
    @RequestMapping("currentFinance")
    public Object currentFinance(String current){
        List<currentFinance> currentFinances = financeService.currentFinance(current);
        return currentFinances;
    }

}
